<!-- 物资与服务 -->
<template>
  <div>
    <iframe :src="attachmentInfoUrl" scrolling="no" width="100%" :height="attachmentHeight" frameborder="0" />
  </div>
</template>
<script>

export default {
  name: 'ZrMaterialService',
  inject: ['prjDetail', 'workDetail'],
  props: {
    prjId: {
      type: String,
      default: '',
      required: true
    },
    selectList: {
      type: Array,
      default: () => [],
      required: true
    },
    isEdit: {
      type: String,
      default: '1',
      required: true
    }
  },
  data() {
    return {
      attachmentHeight: ''
    }
  },
  computed: {
    attachmentInfoUrl() {
      const subPrjList = this.selectList.map(item => item.prjId)
      let parentPrjId = this.newPrjDetail.parentPrjId
      let parentPrjCode = this.newPrjDetail.parentPrjCode
      if (this.newPrjDetail.manageMode === '03') {
          parentPrjId = this.newPrjDetail.prjId
          parentPrjCode = this.newPrjDetail.prjCode
      }
      window.sessionStorage.setItem('subPrjList', JSON.stringify(subPrjList))
      return `${process.env.VUE_APP_ZHONGRUAN_URL}materialServiceBind?prjId=${this.newPrjDetail.prjId}&parentPrjId=${parentPrjId}&parentPrjCode=${parentPrjCode}&isEdit=${this.isEdit}&workItemId=${this.newWorkDetail.workItemID}`
    },
    newPrjDetail() {
      return this.prjDetail()
    },
    newWorkDetail() {
      return this.workDetail()
    }
  },
  async created() {
    window.addEventListener('message', (event) => {
      const base_url = ''
      if (event.origin === base_url) {
        return
      }
      if (event.data.type === 'materialServiceHeight') {
        this.attachmentHeight = event.data.height
      }
    })
  }
}
</script>

<style scoped lang='scss'>
</style>
